package beans;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="news")
public class News {

	@Id
	@GeneratedValue
	private int id;
	private String title;
	private String news;
	private Date date;
	private Date last_update;
	@OneToMany(targetEntity=Comment.class, mappedBy="news", cascade=CascadeType.ALL)
	private List<Comment> comments;

	
    public List<Comment> getComments() {
            return comments;
    }
    public void setComments(List<Comment> comments) {
            this.comments = comments;
    }

	
	@ManyToOne
	@JoinColumn(name="username")
	private User user;
	
	@ManyToMany
	@JoinTable(name="news_tag",
			joinColumns={@JoinColumn(name="news_id")},
			inverseJoinColumns={@JoinColumn(name="tag_id")})
	private List<Tag> tags;
	
	public Date getLast_update() {
		return last_update;
	}
	public void setLast_update(Date last_update) {
		this.last_update = last_update;
	}
	public List<Tag> getTags() {
		return tags;
	}
	public void setTags(List<Tag> tags) {
		this.tags = tags;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getNews() {
		return news;
	}
	public void setNews(String news) {
		this.news = news;
	}
	public Date getDate() {
		return date;
	}
	public void setDate(Date date) {
		this.date = date;
	}
	
}
